#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/dma-mapping.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/cpufreq.h>
#include <linux/io.h>
#include <asm/div64.h>
#include <asm/mach/map.h>
#include <mach/regs-lcd.h>
#include <mach/regs-gpio.h>
#include <mach/fb.h>

static struct fb_info *pbfb_info;

static struct fb_ops pb_fbops = {
    .owner = THIS_MODULE;
	.fb_fillrect	= cfb_fillrect,
	.fb_copyarea	= cfb_copyarea,
	.fb_imageblit	= cfb_imageblit,
};

static int __init lcd_drv_init(void)
{
    dma_addr_t phy_addr;
    /* 1.分配 */
         /* var */
    pbfb_info = framebuffer_alloc(0, NULL);
    /* 2.设置 */
    pbfb_info->var.xres = 800;
    pbfb_info->var.yres = 480;
    pbfb_info->var.bits_per_pixel = 16; // rgb565
    pbfb_info->var.red.offset = 11;
    pbfb_info->var.red.lenth = 5;
    pbfb_info->var.green.offset = 5;
    pbfb_info->var.green.lenth = 6;
    pbfb_info->var.blue.offset = 0;
    pbfb_info->var.blue.lenth = 5;
         /* fix */    
    pbfb_info->fix.smem_len = pbfb_info->var.xres * pbfb_info->var.yres *pbfb_info->var.bits_per_pixel / 8;
	if (pbfb_info->var.bits_per_pixel == 24)
		pbfb_info->fix.smem_len = pbfb_info->var.xres * pbfb_info->var.yres * 4;
        /* fb的虚拟地址 */
    pbfb_info->screen_base = dma_alloc_wc(NULL, pbfb_info->fix.smem_len, &phy_addr, GFP_KERNEL);
    pbfb_info->fix.smem_start = phy_addr;

	pbfb_info->fix.type = FB_TYPE_PACKED_PIXELS;
	pbfb_info->fix.visual = FB_VISUAL_TRUECOLOR;
        /* c. fbops */
	pbfb_info->fbops = &pb_fbops;    
    /* 3.注册 */
    register_framebuffer(pb_fbops);

    /* 4.硬件操作 */



    return 0;
}

static void __exit lcd_drv_exit(void) 
{
    unregister_framebuffer(pb_fbops);
    framebuffer_release(pb_fbops);
}

module_init(lcd_drv_init);
module_exit(lcd_drv_exit);

MODULE_AUTHOR("PB");
MODULE_LICENSE("GPL");

